package cn.wolfcode.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.wolfcode.business.vo.CustomerVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wolfcode.common.annotation.Log;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.enums.BusinessType;
import cn.wolfcode.business.domain.Record;
import cn.wolfcode.business.service.IRecordService;
import cn.wolfcode.common.utils.poi.ExcelUtil;
import cn.wolfcode.common.core.page.TableDataInfo;

/**
 * 拜访客户Controller
 * 
 * @author 2
 * @date 2023-11-05
 */
@RestController
@RequestMapping("/business/record")
public class RecordController extends BaseController
{
    @Autowired
    private IRecordService recordService;

    /**
     * 查询拜访客户列表
     */
    @PreAuthorize("@ss.hasPermi('business:record:list')")
    @GetMapping("/list")
    public AjaxResult list(Record record)
    {
        startPage();
        CustomerVO vo = recordService.selectRecordList(record);
        return AjaxResult.success(vo);
    }

    /**
     * 导出拜访客户列表
     */
//    @PreAuthorize("@ss.hasPermi('business:record:export')")
//    @Log(title = "拜访客户", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Record record)
//    {
//        List<Record> list = recordService.selectRecordList(record);
//        ExcelUtil<Record> util = new ExcelUtil<Record>(Record.class);
//        util.exportExcel(response, list, "拜访客户数据");
//    }

    /**
     * 获取拜访客户详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(recordService.selectRecordById(id));
    }

    /**
     * 新增拜访客户
     */
    @PreAuthorize("@ss.hasPermi('business:record:add')")
    @Log(title = "拜访客户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Record record)
    {
        return toAjax(recordService.insertRecord(record));
    }

    /**
     * 修改拜访客户
     */
    @PreAuthorize("@ss.hasPermi('business:record:edit')")
    @Log(title = "拜访客户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Record record)
    {
        return toAjax(recordService.updateRecord(record));
    }

    /**
     * 删除拜访客户
     */
    @PreAuthorize("@ss.hasPermi('business:record:remove')")
    @Log(title = "拜访客户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recordService.deleteRecordByIds(ids));
    }
}
